package com.data.web.controller.sensor.acc;

import com.data.biz.constant.AccTableResult;
import com.data.biz.service.IBizAccService;
import com.data.biz.vo.SensorVo.acc.AccGraphGroupVo;
import com.data.biz.vo.SensorVo.dip.GraphGroupVo;
import com.data.biz.vo.SensorVo.acc.AccTableVo;
import com.data.web.constant.PageResult;
import com.data.web.constant.ResultVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/sensor/acc")
public class AccController {

    @Autowired
    private IBizAccService accService;


    @ApiOperation(value = "获取加速度多测点数据", notes = "获取加速度多测点数据", httpMethod = "GET", consumes = "application/x-www-form-urlencoded")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "page", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pointId", value = "测点ID", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始时间 20xx-0x-0x", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束时间 20xx-0x-0x", required = true, dataType = "string", paramType = "query"),
    })
    @GetMapping("/getAccTableList")
    public ResultVo<List<AccTableVo>> getAccTableList(Integer page, Integer pageSize, Integer pointId, String startDate, String endDate) {

        AccTableResult result = accService.getAccTableDataByPoint(pointId, startDate, endDate, page, pageSize);
        return ResultVo.success(PageResult.success(result.getTotalCount(),result.getList()));
    }

    @ApiOperation(value = "获取加速度三向曲线图多组数据", notes = "获取曲线图多组数据", httpMethod = "GET", consumes = "application/x-www-form-urlencoded")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pointId", value = "测点ID", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始时间 20xx-0x-0x", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束时间 20xx-0x-0x", required = true, dataType = "string", paramType = "query"),

    })
    @GetMapping("/getAccDataGroupGraph")
    public ResultVo<GraphGroupVo> getaccDataGroupGraph(Integer  pointId, String startDate, String endDate) throws ParseException {

        GraphGroupVo result = accService.getAccDataGroupGraph(pointId,startDate, endDate);
        return ResultVo.success(result);
    }


    @ApiOperation(value = "获取加速度频率功率三向曲线图多组数据", notes = "获取曲线图多组数据", httpMethod = "GET", consumes = "application/x-www-form-urlencoded")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pointId", value = "测点ID", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始时间 20xx-0x-0x", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束时间 20xx-0x-0x", required = true, dataType = "string", paramType = "query"),
    })
    @GetMapping("/getAccDataGroupGraphForPR")
    public ResultVo<AccGraphGroupVo> getaccDataGroupGraphForPR(Integer  pointId, String startDate, String endDate) throws ParseException {
        AccGraphGroupVo result = accService.getAccDataGroupGraphForPR(pointId,startDate, endDate);
        return ResultVo.success(result);
    }


    @ApiOperation(value = "获取加速度统计数据", notes = "获取加速度统计数据", httpMethod = "GET", consumes = "application/x-www-form-urlencoded")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pointId", value = "测点ID", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始时间 20xx-0x-0x", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束时间 20xx-0x-0x", required = true, dataType = "string", paramType = "query"),
    })
    @GetMapping("/getAccDataStatistic")
    public ResultVo<GraphGroupVo> getAccDataStatistic(Integer  pointId, String startDate, String endDate) throws ParseException {

        GraphGroupVo result = accService.getAccDataStatistic(pointId,startDate, endDate);
        return ResultVo.success(result);
    }


    @ApiOperation(value = "获取加速度方向", notes = "获取加速度方向", httpMethod = "GET", consumes = "application/x-www-form-urlencoded")
    @GetMapping("/getTarget")
    public ResultVo<List<String>> getTarget()  {
        List<String> list = new ArrayList<>();
        list.add("X");
        list.add("Y");
        list.add("Z");
        list.add("全部");
        return ResultVo.success(list);
    }



    @ApiOperation(value = "下载加速度数据", notes = "下载加速度数据", httpMethod = "GET", consumes = "application/x-www-form-urlencoded")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pointId", value = "测点ID", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "开始时间 20xx-0x-0x hh:mm:ss", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束时间 20xx-0x-0x hh:mm:ss", required = true, dataType = "string", paramType = "query"),
    })
    @RequestMapping("exportAccExcel")
    public ResponseEntity<byte[]> exportExcel(HttpServletRequest request, HttpServletResponse response, Integer pointId, String startDate, String endDate) {
        return accService.exportAccExcel(request, response,pointId, startDate, endDate);
    }

}

